<template>
    <div>
        <div class="container">
            <el-form ref="form" :model="form" label-width="150px">
                <el-form-item label="关于我们中文">
                    <el-input type="textarea" v-model="form.text"></el-input>
                </el-form-item>
                <el-form-item label="关于我们英文">
                    <el-input type="textarea" v-model="form.e_text"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">更新</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </div>

    </div>
</template>

<script>
import {
    Loading
} from 'element-ui';
import AxiosPost from '../api/index'

export default {
    name: 'LoginLogList',
    data() {
        return {
            form: {
                text: '',
                e_text: '',
                js_img: ''
            },
            form2: {},
            files1: null,

        };
    },
    created() {
        this.getData()
    },
    methods: {
        async getData() {
            let info = await AxiosPost('/admin/shop_set/gywm')
            if (info.code !== 10000) {
                this.$message.error(info.message)
                return false
            } else {
                this.form2 = info.data
                let api = 'https://wjapi.surveydiscovery.com/'
                this.form.text = info.data.text
                this.form.e_text = info.data.e_text
            }
        },
        imgChange1(e) {
            this.files1 = e.target.files[0]
            const formData = new FormData();
            formData.append('js_img', this.files1);
            // 执行上传操作
            this.sendFormData(formData);

        },
        async onSubmit() {
            let option = {}
            this.form.text != this.form2.text ? option.text = this.form.text : '';
            this.form.e_text != this.form2.e_text ? option.e_text = this.form.e_text : '';
            if (Object.keys(option).length !== 0) {
                let info = await AxiosPost('/admin/shop_set/savegywm', option)
                if (info.code !== 10000) {
                    this.$message.error(info.message)
                    return false
                } else {
                    this.getData()
                    this.$message.success('更新成功')
                }
            }

        },
        sendFormData(formData) {
            const _this = this
            const xhr = new XMLHttpRequest();
            xhr.open('POST', 'https://wjapi.surveydiscovery.com/shop_set/savegsjs', true);
            xhr.setRequestHeader('authorization', "Bearer " + localStorage.getItem("uid") + "." + localStorage.getItem("token"));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
                    // 上传成功处理逻辑
                    console.log('上传成功');
                    _this.getData()
                }
            };
            xhr.send(formData);
        }
    }
};
//时间戳转换
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 200px;
    display: inline-block;
}

.table {
    width: 100%;
    font-size: 14px;
}

.red {
    color: #ff0000;
}

.mr10 {
    margin-right: 10px;
}

.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
